package org.example.domain.vo;

import cn.hutool.core.util.ObjectUtil;
import lombok.Data;
import org.example.domain.entity.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class LoginUserVo implements UserDetails {

    private Long id;
    private String token;
    private SysUser user = new SysUser();
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<String> perms = user.getPerms();
        if(ObjectUtil.isNotNull(perms)){
            return perms.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList());
        }
        return null;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
